package com.yeung.exam;

public class newMzina {
    public static void main(String[] args) {
        int sum = 0;
        int x = 0;
        for (int i = 1; i <= 1034; i++) {
            String tmp = i + "";
            if (tmp.contains("4")) {
                x += 1;
//                System.out.println(i);
                continue;
            } else sum += 1;
        }
        System.out.println("-----------------");
        System.out.println("x=" + x);
        System.out.println(sum);

//        System.out.println(NumberOf1Between1AndN_Solution(1034));
        System.out.println(countOne(1034,4));
    }
    static int  countOne(int n, int x) {
        int cnt = 0;
        for (;n > 0;n /= 10) {
            if (n % 10 == x) {
                cnt++;
            }
        }
        return cnt;
    }
    public static int NumberOf1Between1AndN_Solution(int n) {
        int count = 0;//1的个数
        int i = 1;//当前位
        int current = 0, after = 0, before = 0;
        while ((n / i) != 0) {
            current = (n / i) % 10; //高位数字
            before = n / (i * 10); //当前位数字
            after = n - (n / i) * i; //低位数字
            //如果为0,出现1的次数由高位决定,等于高位数字 * 当前位数
            if (current == 0)
                count += before * i;
                //如果为1,出现1的次数由高位和低位决定,高位*当前位+低位+1
            else if (current == 1)
                count += before * i + after + 1;
                //如果大于1,出现1的次数由高位决定,//（高位数字+1）* 当前位数
            else {
                count += (before + 1) * i;
            }
            //前移一位
            i = i * 10;
        }
        return count;
    }
}
